package View;

use strict;

sub get_this_action_url {

    my $rSelf = shift(@_);
    my %hParams = ( @_ );
    my @arPairs = ( );

    if (%hParams) {

	my $stKey;
	foreach $stKey (keys %hParams) {
	    
	    push(@arPairs,$stKey."=".$hParams{$stKey});
	}
    }

    if ($rSelf->{params}->{hidden_fields}) {

	my $rhHiddenFields = $rSelf->{params}->{hidden_fields};

	my $stKey;
	foreach $stKey (keys %$rhHiddenFields) {
	    # TO DO: need a url escape funtion!
	    push(@arPairs,$stKey."=".$rhHiddenFields->{$stKey}) unless exists $hParams{$stKey};
	}
    }

    
    my $stResult = "?".join('&',@arPairs);
	
    return $stResult;
}

sub submit_script {

    my $rSelf = shift(@_);
    my %hParams = ( @_ );
    my @arPairs = ( );

    if (%hParams) {

	my $stKey;
	foreach $stKey (keys %hParams) {
	    
	    push(@arPairs,"document.forms[0].elements['$stKey'].value='".$hParams{$stKey}."'");
	}
    }    

    my $stResult = join(";",@arPairs) . "; document.forms[0].submit(); return false";
    
    return $stResult;
}

1;
